package com.xhwl.logistics.converter.mapstruct;

import com.alibaba.fastjson.JSONObject;
import com.xhwl.common.pojo.cent.device.DeviceProjSupplierCategory;
import com.xhwl.logistics.bo.cent.VehicleIntegratedConfigBO;
import com.xhwl.logistics.bo.cent.VehicleParkingInfoBO;
import com.xhwl.logistics.bo.cent.VehicleSystemInfoBO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueMappingStrategy;

import java.util.List;

@Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface VehicleIntegratedConfigConverter {

    List<VehicleIntegratedConfigBO> deviceProjSupplierCategoryList2VehicleIntegratedConfigBOList(List<DeviceProjSupplierCategory> deviceProjSupplierCategoryList);

    default VehicleIntegratedConfigBO deviceProjSupplierCategory2VehicleIntegratedConfigBO(DeviceProjSupplierCategory deviceProjSupplierCategory) {
        VehicleIntegratedConfigBO vehicleIntegratedConfigBO = new VehicleIntegratedConfigBO();
        VehicleSystemInfoBO vehicleSystemInfoBO = deviceProjSupplierCategory2VehicleSystemInfoBO(deviceProjSupplierCategory);
        VehicleParkingInfoBO vehicleParkingInfoBO = jsonObject2VehicleParkingInfoBO(deviceProjSupplierCategory.getProperties());
        vehicleIntegratedConfigBO.setVehicleSystemInfoBO(vehicleSystemInfoBO);
        vehicleIntegratedConfigBO.setVehicleParkingInfoBO(vehicleParkingInfoBO);
        return vehicleIntegratedConfigBO;
    }

    @Mapping(source = "prodCategoryId", target = "productCategoryId")
    @Mapping(source = "prodAccessId", target = "productAccessId")
    VehicleSystemInfoBO deviceProjSupplierCategory2VehicleSystemInfoBO(DeviceProjSupplierCategory deviceProjSupplierCategory);

    default VehicleParkingInfoBO jsonObject2VehicleParkingInfoBO(JSONObject jsonObject) {
        if (null!=jsonObject) {
            return jsonObject.toJavaObject(VehicleParkingInfoBO.class);
        }
        return new VehicleParkingInfoBO();
    }

}
